var mongoose=require('mongoose');

var orderSchema = new mongoose.Schema({
    user:{
        type:mongoose.Schema.ObjectId,
        ref:'User'
    },
    password:{
        type:String,
        required:true,
        set:function(pass){
            if(!pass || 'string'!==typeof pass)pass='';
            return crypto.createHash('md5').update(pass).digest('hex');
        }
    },
    time:{
        type:Date,
        default:new Date(),
        get: function () {
            var d=this;
            return [d.getFullYear(), d.getMonth()+1, d.getDate()].join('-')+' '+[d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
        }
    }
});

module.exports=mongoose.model('User',orderSchema);